import Api from '@core/http/decorates/api';
import { IList } from '@core/http/IList';
import { AxiosInstance } from 'axios';
import { GetCommentListRes } from './models/GetCommentListRes';

@Api({ prefix: 'comment' })
export class Comment {
  private readonly http: AxiosInstance;

  /**
   * 插入评论
   *
   * @param {string} content
   * @return {*}
   * @memberof Comment
   */
  async insertComment(content: string, noteId: string) {
    return (await this.http.post('insertComment', { content, noteId })).data;
  }

  /**
   * 获得评论
   *
   * @param {number} pageIndex
   * @param {number} pageSize
   * @return {*}
   * @memberof Comment
   */
  async getCommentList(pageIndex: number, pageSize: number, noteId: string) {
    return (
      await this.http.get<IList<GetCommentListRes>>('getCommentList', {
        params: {
          noteId,
          pageIndex,
          pageSize,
        },
      })
    ).data;
  }
}
